package com.tool.btn;

import com.tool.image.ImageMixDeal;
import com.tool.role.RoleData;
import com.tool.role.RoleProperty;
import com.tool.role.RoleReborn;
import com.tool.role.RoleSkill;
import com.tool.tcpimg.UIUtils;
import come.tool.JDialog.TiShiUtil;
import org.cbg.bean.GoodsBackBean;
import org.cbg.frame.TrslationMainJframe;
import org.cbg.panel.TraslationWantSendCardJpanel;
import org.cbg.panel.TraslationWantSentYijishangpinModelJpanel;
import org.come.Frame.OptionsJframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.ExchangeAwardJpanel;
import org.come.Jpanel.FaHuoJpanel;
import org.come.bean.ChangeRoleNameBean;
import org.come.bean.LoginResult;
import org.come.bean.PrivateData;
import org.come.entity.Goodstable;
import org.come.mouslisten.GoodsMouslisten;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FaHuoBtn extends MoBanBtn {

    private FaHuoJpanel faHuoJpanel;

    public static TraslationWantSentYijishangpinModelJpanel jpanel2;

    public FaHuoBtn(String iconpath, int type, String text, FaHuoJpanel faHuoJpanel) {
        super(iconpath, type, UIUtils.COLOR_BTNPUTONG);
        // TODO Auto-generated constructor stub
        setText(text);
        setFont(UIUtils.TEXT_HY88);
        setColors(new Color[]{UIUtils.COLOR_HURTB3,UIUtils.COLOR_HURTB3,UIUtils.COLOR_HURTB3});
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.faHuoJpanel = faHuoJpanel;
    }
    public FaHuoBtn(String iconpath, int type, String text, FaHuoJpanel faHuoJpanel, String SM) {
        super(iconpath, type, UIUtils.COLOR_BLACK);
        // TODO Auto-generated constructor stub
        setText(text);
        setFont(UIUtils.TEXT_HY88);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.faHuoJpanel = faHuoJpanel;
    }

    @Override
    public void chooseyes() {
        // TODO Auto-generated method stub

    }

    @Override
    public void chooseno() {
        // TODO Auto-generated method stub

    }

    @Override
    public void nochoose(MouseEvent e) {
        if ("取 消".equals(getText())) {
            FormsManagement.HideForm(559);
            return;
        }
        String text = faHuoJpanel.getTextCode().getText();
        if (text == null || "".equals(text)) {
            ZhuFrame.getZhuJpanel().addPrompt("输入为空");
            return;
        }
        if ("发 货".equals(getText())) {
            jpanel2.salegoods.setBuyerRoleId(new BigDecimal(text));



            jpanel2.fahuo.setVisible(false);
            jpanel2.sale_quhui.setVisible(false);

            GoodsBackBean backBean = new GoodsBackBean();
            List<BigDecimal> mesIdList = new ArrayList<>();
            backBean.setBuyerRoleId(jpanel2.salegoods.getBuyerRoleId());
            mesIdList.add(jpanel2.salegoods.getSaleid());
            backBean.setIds(mesIdList);
            backBean.setLeiXing("确认发货");

            String sendmes = Agreement.getAgreement().CBGoodDeliverAgreement(
                    GsonUtil.getGsonUtil().getgson().toJson(backBean));
            SendMessageUntil.toServer(sendmes);

            new Thread(()->{
                try {
                    FormsManagement.HideForm(559);
                    Thread.sleep(1000L);
                    TraslationWantSendCardJpanel traslationWantSendCardJpanel = TrslationMainJframe.getTrslationMainJframe().getTrslationMainJpanel().getTranslationMainCardJpanel().getTraslationWantSentJpanel().getTraslationWantSendCardJpanel();
                    traslationWantSendCardJpanel.getTraslationWantSentYijishangpinJpanel().MyShow();
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }).start();

            // 发送消息给服务器
            OptionsJframe.getOptionsJframe().getOptionsJpanel().showBox(TiShiUtil.CBGFahuo, jpanel2, String.format("#R注意：#Y您确定收到了#R %s #Y的货款了吗？确认后买家将收到获取，请您确认收到款后再点确定！",jpanel2.salegoods.getSalename()));

        }
    }

    /** 判断字符串是否含有特殊符号 **/
    public static boolean special(String ChangeName) {
        String[] a = { "!", "|", "*", "&", "@", "#", "$", "%", "^", "/" };
        for (int i = 0; i < a.length; i++) {
            if (ChangeName.indexOf(a[i]) != -1) {
                return false;
            }
        }
        return true;
    }
    /**招募*/
    public void recruit(String text){
        if(!isNumeric(text)){
            ZhuFrame.getZhuJpanel().addPrompt2("请输入正确的数字");
            return;
        }
        SendMessageUntil.toServer(Agreement.getAgreement().hjslAgreement("Z"+text));
        FormsManagement.HideForm(559);
    }

    Pattern pattern = Pattern.compile("[0-9]*");

    /**判断是否是数字*/
    public boolean isNumeric(String str) {
        Matcher isNum = pattern.matcher(str);
        return isNum.matches();
    }
}
